<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" trimDirectiveWhitespaces="true" %>
<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="${applicationScope.webConfig.description}">
    <meta name="Keywords" content="${applicationScope.webConfig.keyWord}">
    <link rel="shortcut icon" href="${applicationScope.webConfig.icon}"/>
    <meta name="author" content="">

    <title>${applicationScope.webConfig.title}</title>

    <!-- Bootstrap Core CSS -->
    <link href="/resource/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="/resource/css/sb-admin.css" rel="stylesheet">

    <!-- Morris Charts CSS -->
    <link href="/resource/css/plugins/morris.css" rel="stylesheet">

    <!--ICheck CSS -->
    <link href="/resource/css/plugins/icheck/skins/flat/orange.css" rel="stylesheet">

    <!--bootstrap-select CSS -->
    <link href="/resource/css/plugins/select/bootstrap-select.min.css" rel="stylesheet">

    <!--toastr CSS -->
    <link href="/resource/css/plugins/toastr/toastr.min.css" rel="stylesheet">

    <!--datatime CSS -->
    <link href="/resource/css/plugins/datetimepicker/bootstrap-datetimepicker.min.css" rel="stylesheet">

    <!--webupload CSS -->
    <link href="/resource/css/plugins/webupload/webuploader.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="/resource/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        #web-config-form a {
            color: #333
        }
        .webuploader-pick {
            background: url("${applicationScope.webConfig.icon}") no-repeat center;
        }
    </style>
</head>

<body>

<div id="wrapper">

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <%--引入导航--%>
        <jsp:include page="topMenuItems.jsp"></jsp:include>
        <jsp:include page="sidebarMenuItems.jsp">
            <jsp:param name="active" value="webConfig"></jsp:param>
        </jsp:include>
    </nav>

    <div id="page-wrapper">

        <div class="container-fluid">
            <!-- Page Heading -->
            <div class="row">
                <h3 class="page-header" style="margin: 20px 0px 25px">
                    通用配置
                    <small>站点设置</small>
                </h3>
            </div>
            <!-- /.row -->
            <form role="form" id="web-config-form">
                <div class="row">
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label>标题</label>
                            <input name="title" class="form-control" value="${applicationScope.webConfig.title}">
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label>关键词</label>
                            <input name="keyWord" class="form-control"
                                   value="${applicationScope.webConfig.keyWord}"></textarea>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label>描述</label>
                            <textarea name="description" class="form-control"
                                      rows="5">${applicationScope.webConfig.description}</textarea>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><a href="https://tongji.baidu.com" target="_blank"> 百度统计代码</a></label>
                            <textarea name="baiduToneji" class="form-control"
                                      rows="5">${applicationScope.webConfig.baiduToneji}</textarea>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><a href="http://www.umeng.com/" target="_blank">友盟+统计代码</a></label>
                            <textarea name="youmeng" class="form-control"
                                      rows="5">${applicationScope.webConfig.youmeng}</textarea>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label><a href="http://zhanzhang.baidu.com" target="_blank">百度站长</a></label>
                            <textarea name="baiduZhanzhang" class="form-control"
                                      rows="5">${applicationScope.webConfig.baiduZhanzhang}</textarea>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6">
                        <div class="form-group">
                            <label>管理后台标题</label>
                            <input name="adminTitle" class="form-control" value="${applicationScope.webConfig.adminTitle}">
                        </div>
                    </div>
                    <div class="col-lg-6"></div>
                </div>

                <!-- /.row -->
                <div class="row">
                    <div class="col-lg-12">
                        <div class="form-group">
                            <label>icon</label>
                            <input type="hidden" name="icon" id="input-icon" class="form-control"
                                   value="${applicationScope.webConfig.icon}"/>
                            <div id="uploader" class="wu-example">
                                <!--用来存放文件信息-->
                                <div id="thelist" class="uploader-list">

                                </div>
                                <div class="btns">
                                    <div id="picker"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-12">
                        <button onclick="save()" type="button" class="btn btn-default btn-success">保存</button>
                    </div>
                </div>
            </form>
            <!-- /.row-->
        </div>
        <!-- /.container-fluid -->

    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->
<jsp:include page="modal.jsp"/>

<!-- jQuery -->
<script src="/resource/js/jquery.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/resource/js/bootstrap.min.js"></script>

<!-- Morris Charts JavaScript -->
<script src="/resource/js/template-web.js"></script>
<script src="/resource/js/plugins/icheck/icheck.min.js"></script>
<script src="/resource/js/plugins/paginator/bootstrap-paginator.min.js"></script>
<script src="/resource/js/plugins/select/bootstrap-select.min.js"></script>
<script src="/resource/js/plugins/bootbox/bootbox.min.js"></script>
<script src="/resource/js/plugins/toastr/toastr.min.js"></script>
<script src="/resource/js/plugins/layer/layer.js"></script>
<script src="/resource/js/plugins/datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script src="/resource/js/plugins/datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="/resource/js/CommonPage.js"></script>
<script src="/resource/js/plugins/webupload/webuploader.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var $list = $("#thelist");   //这几个初始化全局的百度文档上没说明，好蛋疼。
        var $btn = $("#ctlBtn");   //开始上传
        var uploader = WebUploader.create({

            // swf文件路径
            swf: '/resource/js/plugins/webupload/Uploader.swf',

            // 文件接收服务端。
            server: '/admin/upload.do',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: {
                id: '#picker',
                innerHTML: '<span style="color: black;font-size: 22px" class="glyphicon glyphicon-cloud-upload"></span>'
            },
            auto: true,//自动上传

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: true,

            method: 'POST',
        });
        uploader.on('uploadSuccess', function (file, response) {
            $('.webuploader-pick').css('background', 'url("' + response.data + '") no-repeat center')
            $('#input-icon').val(response.data)
            layer.msg(file.name + '已成功上传', {icon: 1});
            save();
        });
        uploader.on('uploadError', function (file) {
            layer.msg(file.name + '上传失败。', {icon: 5});
        });

    })


    function save() {
        $.post('/admin/webConfig/merge.do', $('#web-config-form').serialize(), function (data) {
            if (data.ret == 1) {
                layer.msg('保存成功', {icon: 1});
            } else {
                layer.msg('保存失败', {icon: 5});
            }

        })
    }
</script>
</body>
</html>
